import { TweenLite } from "../TweenLite";
import { SimpleTimeline } from "./SimpleTimeline";
//class TweenCore
    
    export  class TweenCore
    {
        constructor(arg1: number=0, arg2: Object=null)
        {
            
            this.vars = arg2 == null ? {} : arg2;
            var loc2;
            this.cachedTotalDuration = loc2 = arg1;
            this.cachedDuration = loc2;
            this._delay = this.vars.delay ? Number(this.vars.delay) : 0;
            this.cachedTimeScale = this.vars.timeScale ? Number(this.vars.timeScale) : 1;
            this.active = Boolean(arg1 == 0 && this._delay == 0 && !(this.vars.immediateRender == false));
            this.cachedTime = loc2 = 0;
            this.cachedTotalTime = loc2;
            this.data = this.vars.data;
            if (!TweenCore._classInitted) 
            {
                if (isNaN(TweenLite.rootFrame)) 
                {
                    TweenLite.initClass();
                    TweenCore._classInitted = true;
                }
                else 
                {
                    return;
                }
            }
            var loc1=this.vars.timeline is SimpleTimeline ? this.vars.timeline : this.vars.useFrames ? TweenLite.rootFramesTimeline : TweenLite.rootTimeline;
            this.cachedStartTime = loc1.cachedTotalTime + this._delay;
            loc1.addChild(this);
            if (this.vars.reversed) 
            {
                this.cachedReversed = true;
            }
            if (this.vars.paused) 
            {
                this.paused = true;
            }
            return;
        }

        public complete(arg1: Boolean=false, arg2: Boolean=false): void
        {
            if (!arg1) 
            {
                this.renderTime(this.totalDuration, arg2, false);
                return;
            }
            if (this.timeline.autoRemoveChildren) 
            {
                this.setEnabled(false, false);
            }
            else 
            {
                this.active = false;
            }
            if (!arg2) 
            {
                if (this.vars.onComplete && this.cachedTotalTime == this.cachedTotalDuration && !this.cachedReversed) 
                {
                    this.vars.onComplete.apply(null, this.vars.onCompleteParams);
                }
                else if (this.cachedReversed && this.cachedTotalTime == 0 && this.vars.onReverseComplete) 
                {
                    this.vars.onReverseComplete.apply(null, this.vars.onReverseCompleteParams);
                }
            }
            return;
        }

        public invalidate(): void
        {
            return;
        }

        public setEnabled(arg1: Boolean, arg2: Boolean=false): Boolean
        {
            this.gc = !arg1;
            if (arg1) 
            {
                this.active = Boolean(!this.cachedPaused && this.cachedTotalTime > 0 && this.cachedTotalTime < this.cachedTotalDuration);
                if (!arg2 && this.cachedOrphan) 
                {
                    this.timeline.addChild(this);
                }
            }
            else 
            {
                this.active = false;
                if (!arg2 && !this.cachedOrphan) 
                {
                    this.timeline.remove(this, true);
                }
            }
            return false;
        }

        protected setDirtyCache(arg1: Boolean=true): void
        {
            var loc1=arg1 ? this : this.timeline;
            while (loc1) 
            {
                loc1.cacheIsDirty = true;
                loc1 = loc1.timeline;
            }
            return;
        }

        protected setTotalTime(arg1: number, arg2: Boolean=false): void
        {
            var loc1=NaN;
            var loc2=NaN;
            if (this.timeline) 
            {
                loc1 = this._pauseTime || this._pauseTime == 0 ? this._pauseTime : this.timeline.cachedTotalTime;
                if (this.cachedReversed) 
                {
                    loc2 = this.cacheIsDirty ? this.totalDuration : this.cachedTotalDuration;
                    this.cachedStartTime = loc1 - (loc2 - arg1) / this.cachedTimeScale;
                }
                else 
                {
                    this.cachedStartTime = loc1 - arg1 / this.cachedTimeScale;
                }
                if (!this.timeline.cacheIsDirty) 
                {
                    this.setDirtyCache(false);
                }
                if (this.cachedTotalTime != arg1) 
                {
                    this.renderTime(arg1, arg2, false);
                }
            }
            return;
        }

        public kill(): void
        {
            this.setEnabled(false, false);
            return;
        }

        public get delay(): number
        {
            return this._delay;
        }

        public set delay(arg1: number)
        {
            this.startTime = this.startTime + (arg1 - this._delay);
            this._delay = arg1;
            return;
        }

        public get duration(): number
        {
            return this.cachedDuration;
        }

        public set duration(arg1: number)
        {
            var loc1;
            this.cachedTotalDuration = loc1 = arg1;
            this.cachedDuration = loc1;
            this.setDirtyCache(false);
            return;
        }

        public get totalDuration(): number
        {
            return this.cachedTotalDuration;
        }

        public set totalDuration(arg1: number)
        {
            this.duration = arg1;
            return;
        }

        public get currentTime(): number
        {
            return this.cachedTime;
        }

        public set currentTime(arg1: number)
        {
            this.setTotalTime(arg1, false);
            return;
        }

        public get totalTime(): number
        {
            return this.cachedTotalTime;
        }

        public set totalTime(arg1: number)
        {
            this.setTotalTime(arg1, false);
            return;
        }

        public get startTime(): number
        {
            return this.cachedStartTime;
        }

        public get reversed(): Boolean
        {
            return this.cachedReversed;
        }

        public set reversed(arg1: Boolean)
        {
            if (arg1 != this.cachedReversed) 
            {
                this.cachedReversed = arg1;
                this.setTotalTime(this.cachedTotalTime, true);
            }
            return;
        }

        public restart(arg1: Boolean=false, arg2: Boolean=true): void
        {
            this.reversed = false;
            this.paused = false;
            this.setTotalTime(arg1 ? -this._delay : 0, arg2);
            return;
        }

        public get paused(): Boolean
        {
            return this.cachedPaused;
        }

        public set paused(arg1: Boolean)
        {
            if (!(arg1 == this.cachedPaused) && this.timeline) 
            {
                if (arg1) 
                {
                    this._pauseTime = this.timeline.rawTime;
                }
                else 
                {
                    this.cachedStartTime = this.cachedStartTime + (this.timeline.rawTime - this._pauseTime);
                    this._pauseTime = NaN;
                    this.setDirtyCache(false);
                }
                this.cachedPaused = arg1;
                this.active = Boolean(!this.cachedPaused && this.cachedTotalTime > 0 && this.cachedTotalTime < this.cachedTotalDuration);
            }
            if (!arg1 && this.gc) 
            {
                this.setTotalTime(this.cachedTotalTime, false);
                this.setEnabled(true, false);
            }
            return;
        }

        public play(): void
        {
            this.reversed = false;
            this.paused = false;
            return;
        }

        public pause(): void
        {
            this.paused = true;
            return;
        }

        public resume(): void
        {
            this.paused = false;
            return;
        }

        public set startTime(arg1: number)
        {
            var loc1=Boolean(!(this.timeline == null) && (!(arg1 == this.cachedStartTime) || this.gc));
            this.cachedStartTime = arg1;
            if (loc1) 
            {
                this.timeline.addChild(this);
            }
            return;
        }

        public reverse(arg1: Boolean=true): void
        {
            this.reversed = true;
            if (arg1) 
            {
                this.paused = false;
            }
            else if (this.gc) 
            {
                this.setEnabled(true, false);
            }
            return;
        }

        public renderTime(arg1: number, arg2: Boolean=false, arg3: Boolean=false): void
        {
            return;
        }

        public static /* const */version: number=1.382;

        protected /* var */_delay: number;

        protected /* var */_hasUpdate: Boolean;

        protected /* var */_rawPrevTime: number=-1;

        protected /* var */_pauseTime: number;

        public /* var */vars: Object;

        public /* var */gc: Boolean;

        public /* var */initted: Boolean;

        public /* var */timeline: SimpleTimeline;

        public /* var */cachedStartTime: number;

        public /* var */cachedTime: number;

        public /* var */cachedTotalTime: number;

        public /* var */cachedDuration: number;

        public /* var */cachedTotalDuration: number;

        public /* var */cachedTimeScale: number;

        public /* var */cachedReversed: Boolean;

        public /* var */nextNode: TweenCore;

        public /* var */prevNode: TweenCore;

        public /* var */cachedOrphan: Boolean;

        public /* var */cachedPaused: Boolean;

        public /* var */data;

        public /* var */cacheIsDirty: Boolean;

        public /* var */active: Boolean;

        protected static /* var */_classInitted: Boolean;
    }
